#!/bin/bash

# chkconfig: 35 95 1

# description: script to manage ramdisk

# 管理内存盘的脚本

datas=%SIZELIST%

function start() {
	oldIFS=$IFS
	IFS=,
	for onemount in $datas; do
		mntPath=$(echo $onemount | cut -d: -f1)
		mntSize=$(echo $onemount | cut -d: -f2)

		if ! [ -d $mntPath ]; then
			mkdir -p $mntPath
		fi
		mount -t tmpfs -o size=$mntSize tmpfs $mntPath
	done
	IFS=$oldIFS

	/etc/init.d/yjtftpuser > /dev/null
}

function stop() {
	oldIFS=$IFS
	IFS=,
	for onemount in $datas; do
		mntPath=$(echo $onemount | cut -d: -f1)

		mountpoint -q $mntPath
		if [ $? -eq 0 ]; then
			umount $mntPath
		fi
	done
	IFS=$oldIFS
}

function status() {
	echo "not support yet"
}

case $1 in
	start)
		start
		;;
	stop)
		stop
		;;
	restart)
		stop
		start
		;;
	status)
		status
		;;
	default)
		echo "unknown $1"
		echo "Usage: $0 {start|stop|restart|status}"
		;;
esac

